﻿Public Class PWDFORM

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If txt旧密码.Text.Trim = "" Then
            ShowMessageBox("不能为空")
            txt旧密码.Focus()
            Return
        End If

        If Not 验证密码是否正确() Then
            txt旧密码.Focus()
            Return
        End If

        If txt新密码1.Text.Trim = "" Then
            ShowMessageBox("不能为空")
            txt新密码1.Focus()
            Return
        End If

        If txt新密码2.Text.Trim = "" Then
            ShowMessageBox("不能为空")
            txt新密码2.Focus()
            Return
        End If

        If txt新密码2.Text.Trim <> txt新密码1.Text.Trim Then
            ShowMessageBox("两次不相等")
            txt新密码2.Focus()
            Return
        End If

        Dim sql As String = "UPDATE XSCPWD SET PWD=?"
        Dim CMD As New ADODB.Command
        CMD.CommandText = sql
        Dim pa As ADODB.Parameter = CMD.CreateParameter(, ADODB.DataTypeEnum.adWChar, ADODB.ParameterDirectionEnum.adParamInput, 50)
        pa.Value = Me.txt新密码1.Text.Trim
        CMD.Parameters.Append(pa)

        If ct.ExcCommand(CMD) Then
            ShowMessageBox("修改成功")
        Else
            ShowMessageBox("修改失败")
        End If
        Me.Close()
    End Sub

    Private Function 验证密码是否正确()
        验证密码是否正确 = False
        Dim sql As String = "select * from XSCPWD where PWD=?"
        Dim CMD As New ADODB.Command
        CMD.CommandText = sql
        Dim pa As ADODB.Parameter = CMD.CreateParameter(, ADODB.DataTypeEnum.adWChar, ADODB.ParameterDirectionEnum.adParamInput, 50)
        pa.Value = Me.txt旧密码.Text.Trim
        CMD.Parameters.Append(pa)

        Dim rs As ADODB.Recordset = ct.ExcCommandAsRs(CMD)
        If rs Is Nothing Then
            ShowMessageBox("密码不正确")
            txt旧密码.Text = ""
            txt旧密码.Focus()
            Exit Function
        End If

        If rs.EOF Then
            rs.Close()
            System.Runtime.InteropServices.Marshal.ReleaseComObject(rs)
            ShowMessageBox("密码不正确")

            txt旧密码.Text = ""
            txt旧密码.Focus()
            Exit Function
        End If

        rs.Close()
        System.Runtime.InteropServices.Marshal.ReleaseComObject(rs)

        验证密码是否正确 = True
    End Function
End Class
